## --------------------------------------------------------------------------

def EditData(frame,options):
    # edit frame

    print "\nEdit",
    PrintFrame(frame)

    if options.deltat:
        print "\nmin",
        print "press  temp0  temp1   HV1    HV2    HV3  deltaT   hour   ddeltaT"
            
        for i in range(0,60-1): # overflow at minute 59: do not correct
            linesum = 0
            print "\n %02i" %(i), 
            for j in range(18,26):
                print "%5i " %(frame[i][j]),
            if i > 0:
                ddT = frame[i][24]-frame[i-1][24]
            else:
                ddT = frame[i][24]
                
            print "%5i " %ddT,
                # delta delta T should be ~ 1092
            if (ddT > 1400) or (ddT < 1000):
                if i == 0:
                    frame[0][24] = 1200
                else:
                    frame[i][24] = frame[i-1][24] + 1092
                print "corrected", frame[i][24], 
        print "Delta T\n"
                

    # check / set hour of BIN data
    if options.hour:
        hour = frame[0][25]
        if options.hour >= 0 :
            print "set hour to ", options.hour
            for i in range(1,60):
                if hour != frame[i][25] + (i==59):
                    frame[i][25] = hour + (i==59)
        else:
            print "check hour = ", hour
            for i in range(1,60):
                if hour != (frame[i][25] - (i==59)):
                    print "min:", i, "hour:", frame[i][25], "should be ", hour + (i==59)

    # delete data from section A in row_a
    if options.row_a:
        if options.row_a >=0:
            for j in range(0,6):
                frame[options.row_a][j] = 0
                
    # delete data from section B in row_b
    if options.row_b:
        if options.row_b >=0:
            for j in range(6,12):
                frame[options.row_b][j] = 0
                
    # delete data from section C in row_c
    if options.row_c:
        if options.row_c >=0:
            for j in range(12,18):
                frame[options.row_c][j] = 0
                
    # delete data from section A
    if options.clear_a:
        for i in range(0,60):
            for j in range(0,6):
                frame[i][j] = 0

    # delete data from section B
    if options.clear_b:
        for i in range(0,60):
            for j in range(6,12):
                frame[i][j] = 0

    # delete data from section C
    if options.clear_c:
        for i in range(0,60):
            for j in range(12,18):
                frame[i][j] = 0
        
    # delete extreme values (spikes)
    for i in range(0,60):
        for j in range(0,18):
            if frame[i][j] < options.min:
                frame[i][j] = 0
            if frame[i][j] > options.max:
                frame[i][j] = 0

    # delete lines if only one counter <> 0
    for i in range(0,60):
        num = 0
        for j in range(0,18):
            if frame[i][j] == 0:
                num += 1

        if (num == 17):
            #print "deleting minute %i because of %i zeroes" %(i, num)
            for j in range(0,18):
                frame[i][j] = 0
            
    # delete data from row
    #print "row: %i >=0: %i" %(options.row, options.row >= 0)
    if options.row >=0:
        print "row: %i >=0 : %i" %(options.row, options.row >= 0)
        for j in range(0,18):
            frame[options.row][j] = 0

    # delete data from column
    #print "column: %i >=0: %i" %(options.column, options.column >= 0)
    if options.column >=0:
        print "column: %i >=0 : %i" %(options.column, options.column >= 0)
        for i in range(0,60):
            frame[i][options.column-1] = 0
        
    # delete pressure from row
    #print "row: %i >=0: %i" %(options.row, options.row >= 0)
    if options.pressure >= 0:
        print "pressure: %i >=0 : %i" %(options.pressure, options.pressure >= 0)
        if options.pressure > 0 and options.pressure < 60:
            if frame[options.pressure-1][18] > 0 and frame[options.pressure-1][18] < 20000:
                frame[options.pressure][18] = frame[options.pressure-1][18]
            elif frame[options.pressure+1][18] > 0  and frame[options.pressure+1][18] < 20000: 
                frame[options.pressure][18] = frame[options.pressure+1][18]
            else:
                frame[options.pressure][18] = 0
        elif options.pressure > 0:
            if frame[options.pressure-1][18] > 0 and frame[options.pressure-1][18] < 20000:
                frame[options.pressure][18] = frame[options.pressure-1][18]
            else:
                frame[options.pressure][18] = 0
        elif options.pressure < 60:
            if frame[options.pressure+1][18] > 0 and frame[options.pressure+1][18] < 20000:
                frame[options.pressure][18] = frame[options.pressure+1][18]
            else:
                frame[options.pressure][18] = 0
        else:
            frame[options.pressure][18] = 0

    return(frame)
    
